{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# api文档\n",
    "- 地理/逆地理编码\n",
    "- 路径规划\n",
    "- 行政区域查询\n",
    "- 搜索POI\n",
    "- IP定位\n",
    "- 批量请求接口\n",
    "- 静态地图坐标转换\n",
    "- 天气查询\n",
    "- 输入提示\n",
    "- 交通态势\n",
    "- 地理围栏\n",
    "- 轨迹纠偏\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<style>\n",
       "/* 本电子讲义使用之CSS */\n",
       "div.code_cell {\n",
       "    background-color: #e5f1fe;\n",
       "}\n",
       "div.cell.selected {\n",
       "    background-color: #effee2;\n",
       "    font-size: 2rem;\n",
       "    line-height: 2.4rem;\n",
       "}\n",
       "div.cell.selected .rendered_html table {\n",
       "    font-size: 2rem !important;\n",
       "    line-height: 2.4rem !important;\n",
       "}\n",
       ".rendered_html pre code {\n",
       "    background-color: #C4E4ff;   \n",
       "    padding: 2px 25px;\n",
       "}\n",
       ".rendered_html pre {\n",
       "    background-color: #99c9ff;\n",
       "}\n",
       "div.code_cell .CodeMirror {\n",
       "    font-size: 2rem !important;\n",
       "    line-height: 2.4rem !important;\n",
       "}\n",
       ".rendered_html img, .rendered_html svg {\n",
       "    max-width: 50%;\n",
       "    height: auto;\n",
       "    float: center;\n",
       "}\n",
       "/* Gradient transparent - color - transparent */\n",
       "hr {\n",
       "    border: 0;\n",
       "    border-bottom: 1px dashed #ccc;\n",
       "}\n",
       ".emoticon{\n",
       "    font-size: 5rem;\n",
       "    line-height: 4.4rem;\n",
       "    text-align: center;\n",
       "    vertical-align: middle;\n",
       "}\n",
       "\n",
       "</style>\n"
      ],
      "text/plain": [
       "<IPython.core.display.HTML object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "%%html\n",
    "<style>\n",
    "/* 本电子讲义使用之CSS */\n",
    "div.code_cell {\n",
    "    background-color: #e5f1fe;\n",
    "}\n",
    "div.cell.selected {\n",
    "    background-color: #effee2;\n",
    "    font-size: 2rem;\n",
    "    line-height: 2.4rem;\n",
    "}\n",
    "div.cell.selected .rendered_html table {\n",
    "    font-size: 2rem !important;\n",
    "    line-height: 2.4rem !important;\n",
    "}\n",
    ".rendered_html pre code {\n",
    "    background-color: #C4E4ff;   \n",
    "    padding: 2px 25px;\n",
    "}\n",
    ".rendered_html pre {\n",
    "    background-color: #99c9ff;\n",
    "}\n",
    "div.code_cell .CodeMirror {\n",
    "    font-size: 2rem !important;\n",
    "    line-height: 2.4rem !important;\n",
    "}\n",
    ".rendered_html img, .rendered_html svg {\n",
    "    max-width: 50%;\n",
    "    height: auto;\n",
    "    float: center;\n",
    "}\n",
    "/* Gradient transparent - color - transparent */\n",
    "hr {\n",
    "    border: 0;\n",
    "    border-bottom: 1px dashed #ccc;\n",
    "}\n",
    ".emoticon{\n",
    "    font-size: 5rem;\n",
    "    line-height: 4.4rem;\n",
    "    text-align: center;\n",
    "    vertical-align: middle;\n",
    "}\n",
    "\n",
    "</style>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 地理/逆地理\n",
    "- 地理编码/逆地理编码 API 是通过 HTTP/HTTPS 协议访问远程服务的接口，提供结构化地址与经纬度之间的相互转化的能力。\n",
    "\n",
    "结构化地址的定义： 首先，地址肯定是一串字符，内含国家、省份、城市、区县、城镇、乡村、街道、门牌号码、屋邨、大厦等建筑物名称。按照由大区域名称到小区域名称组合在一起的字符。一个有效的地址应该是独一无二的。注意：针对大陆、港、澳地区的地理编码转换时可以将国家信息选择性的忽略，但省、市、城镇等级别的地址构成是不能忽略的。暂时不支持返回台湾省的详细地址信息。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [],
   "source": [
    "import requests #用於API HTTP requests\n",
    "# 使用python字典构造 parameters 请求参数\n",
    "# API使用请求参数\n",
    "key ='d9d5fa5d72ce3bcf4a2fee373f2e81af' # 高德地图API 获取Key\n",
    "def geo(address:str,city=None)-> dict:\n",
    "    \"\"\"获取地理编码\n",
    "    address可填入国家、省份、城市、区县、城镇、乡村、街道、门牌号码、屋邨、大厦等建筑物名称\n",
    "    填入address对应city即可查询具体经纬度\n",
    "    \"\"\"\n",
    "    parameters = {'key':key,\n",
    "                  'city':city,#(可选)\n",
    "                  'citylimit': True,\n",
    "                  'address':address\n",
    "                   } \n",
    "    r = requests.get (\"https://restapi.amap.com/v3/geocode/geo?parameters\", params=parameters)\n",
    "    data = r.json()['geocodes'][0]['location']\n",
    "    return data\n",
    "\n",
    "# 查询关键字(必填)   查询城市(可选)   仅返回指定城市数据(可选)\n",
    "\n",
    "\n",
    "\n",
    "# requests 模塊\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'113.679287,23.632575'"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "geo(\"广东省广州市从化区中山大学南方学院\")\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'113.632401,23.616941'"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "geo(\"广东省广州市从化区温泉镇政府\",\"广州\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 路径规划\n",
    "- 路径规划API是一套以HTTP形式提供的步行、公交、驾车查询及行驶距离计算接口，返回JSON 或 XML格式的查询数据，用于实现路径规划功能的开发。 由于道路/数据/算法的变更，很可能存在间隔一段时间后请求相同起终点的经纬度返回不同结果。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 161,
   "metadata": {},
   "outputs": [],
   "source": [
    "def walking(origin:str,destination:str)->dict:\n",
    "    \"\"\"路径规划\n",
    "    输入起始点和终止点经纬度数据可获取路线规划\n",
    "    可通过geo()函数查询具体地点的经纬度\"\"\"\n",
    "    parameters = {\n",
    "        'key':key,\n",
    "        'origin':origin,\n",
    "        'destination':destination,\n",
    "        'output':'json'\n",
    "    }\n",
    "    r = requests.get(\"https://restapi.amap.com/v3/direction/walking?parameters\",params = parameters)\n",
    "    data = r.json()['route']['paths'][0]['steps']\n",
    "    for i in range(0,len(data)):\n",
    "        print(data[int(i)]['instruction'])\n",
    "    \n",
    "#     print(b[int(i)]['instruction'])\n",
    "    \n",
    "# a = walking(geo(\"广东省广州市从化区中山大学南方学院\",\"广州\"),geo(\"广东省广州市从化区温泉镇政府\",\"广州\"))\n",
    "# b = a\n",
    "# for i in range(0,len(b)):\n",
    "#     print(b[int(i)]['instruction'])\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 162,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "向南步行161米右转\n",
      "向西步行99米左转\n",
      "向南步行237米左转\n",
      "向南步行498米向右前方行走\n",
      "沿源富街向西南步行1568米直行\n",
      "沿源湖街向西步行784米右转\n",
      "沿龙泉路向西北步行1723米向左前方行走\n",
      "沿龙泉路向西步行67米向左前方行走\n",
      "沿温泉大道向西步行22米右转\n",
      "步行13米左转\n",
      "沿温泉大道向西南步行1425米右转\n",
      "向西北步行96米右转\n",
      "向北步行66米到达目的地\n"
     ]
    }
   ],
   "source": [
    "walking(geo(\"广东省广州市从化区中山大学南方学院\",\"广州\"),geo(\"广东省广州市从化区温泉镇政府\",\"广州\"))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 行政区域查询\n",
    "- 行政区域查询是一类简单的HTTP接口，根据用户输入的搜索条件可以帮助用户快速的查找特定的行政区域信息。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [],
   "source": [
    "def district(keywords:str):\n",
    "    \"\"\"行政区域查询\n",
    "    输入省份即可得到对于行政区域\"\"\"\n",
    "    parameters = {\n",
    "        'key':key,\n",
    "        'keywords':keywords,\n",
    "        \"subdistrict\":\"3\",\n",
    "        'output':'json'\n",
    "    }\n",
    "    r = requests.get (\"https://restapi.amap.com/v3/config/district?parameters\", params=parameters)\n",
    "    data = r.json()['districts'][0]['districts']\n",
    "    print(\"----\"+keywords + \"有以下几个行政区域----\")\n",
    "    for i in data:\n",
    "        print(i['name'])\n",
    "    return \n",
    "    \n",
    "    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "----广东有以下几个行政区域----\n",
      "肇庆市\n",
      "佛山市\n",
      "汕头市\n",
      "惠州市\n",
      "深圳市\n",
      "珠海市\n",
      "湛江市\n",
      "阳江市\n",
      "汕尾市\n",
      "潮州市\n",
      "江门市\n",
      "云浮市\n",
      "东沙群岛\n",
      "茂名市\n",
      "河源市\n",
      "梅州市\n",
      "东莞市\n",
      "揭阳市\n",
      "清远市\n",
      "韶关市\n",
      "广州市\n",
      "中山市\n"
     ]
    }
   ],
   "source": [
    "district('广东')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 搜索POI\n",
    "- 搜索服务API是一类简单的HTTP接口，提供多种查询POI信息的能力，其中包括关键字搜索、周边搜索、多边形搜索、ID查询四种筛选机制。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [],
   "source": [
    "def poi(keywords:str,city:str):\n",
    "    \"\"\"搜索POI\n",
    "    输入keywords关键词\n",
    "    输入搜索的范围城市city\n",
    "    即可得到相关信息的表格\"\"\"\n",
    "    parameters = {\n",
    "        'key':key,\n",
    "        'city':city,\n",
    "        'keywords':keywords,\n",
    "#         \"types\":\"生活服务\",\n",
    "        'output':'json',\n",
    "        \n",
    "    }\n",
    "    r = requests.get (\"https://restapi.amap.com/v3/place/text?parameters\", params=parameters)\n",
    "    data = r.json()\n",
    "    pois = []\n",
    "    pois.extend(data['pois'])\n",
    "    import pandas as pd\n",
    "    df_input = pd.DataFrame(pois)\n",
    "    return df_input\n",
    "#     if out == True:\n",
    "#         df_input['keywords']=keywords\n",
    "# #         select_fields = \"keywords\tid\tname\ttype\ttypecode\tlocation\ttel\tpname\tpcode\tcityname\tcitycode\tadname\tadcode\".split(\"\\t\")\n",
    "# #         df = df_input[select_fields]\n",
    "# #         df = df.assign( 经 = [x.split(',')[0] for x in df['location']])\n",
    "# #         df = df.assign( 纬 = [x.split(',')[1] for x in df['location']])\n",
    "#         df.to_csv(\"keywords.csv\", encoding=\"utf8\", sep='\\t') \n",
    "#     else:\n",
    "        \n",
    "    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>id</th>\n",
       "      <th>parent</th>\n",
       "      <th>childtype</th>\n",
       "      <th>name</th>\n",
       "      <th>type</th>\n",
       "      <th>typecode</th>\n",
       "      <th>biz_type</th>\n",
       "      <th>address</th>\n",
       "      <th>location</th>\n",
       "      <th>tel</th>\n",
       "      <th>...</th>\n",
       "      <th>cityname</th>\n",
       "      <th>adname</th>\n",
       "      <th>importance</th>\n",
       "      <th>shopid</th>\n",
       "      <th>shopinfo</th>\n",
       "      <th>poiweight</th>\n",
       "      <th>photos</th>\n",
       "      <th>biz_ext.rating</th>\n",
       "      <th>biz_ext.cost</th>\n",
       "      <th>biz_ext.meal_ordering</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>B0FFKJOM0K</td>\n",
       "      <td>[]</td>\n",
       "      <td>[]</td>\n",
       "      <td>瑞幸咖啡</td>\n",
       "      <td>餐饮服务;餐饮相关场所;餐饮相关</td>\n",
       "      <td>050000</td>\n",
       "      <td>diner</td>\n",
       "      <td>梅界路237号奥园广场商业街121号</td>\n",
       "      <td>113.515126,22.282482</td>\n",
       "      <td>18529169274</td>\n",
       "      <td>...</td>\n",
       "      <td>珠海市</td>\n",
       "      <td>香洲区</td>\n",
       "      <td>[]</td>\n",
       "      <td>[]</td>\n",
       "      <td>0</td>\n",
       "      <td>[]</td>\n",
       "      <td>[{'url': 'http://store.is.autonavi.com/showpic...</td>\n",
       "      <td>4.0</td>\n",
       "      <td>17.00</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>B0FFJGBKD9</td>\n",
       "      <td>B0FFHGLFI2</td>\n",
       "      <td>202</td>\n",
       "      <td>瑞幸咖啡</td>\n",
       "      <td>餐饮服务;餐饮相关场所;餐饮相关</td>\n",
       "      <td>050000</td>\n",
       "      <td>diner</td>\n",
       "      <td>前进二路流塘商务大厦B座流塘湾购物中心一楼A12铺</td>\n",
       "      <td>113.890741,22.581641</td>\n",
       "      <td>[]</td>\n",
       "      <td>...</td>\n",
       "      <td>深圳市</td>\n",
       "      <td>宝安区</td>\n",
       "      <td>[]</td>\n",
       "      <td>[]</td>\n",
       "      <td>0</td>\n",
       "      <td>[]</td>\n",
       "      <td>[{'url': 'http://store.is.autonavi.com/showpic...</td>\n",
       "      <td>3.5</td>\n",
       "      <td>24.00</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>B0FFJD4OEM</td>\n",
       "      <td>[]</td>\n",
       "      <td>[]</td>\n",
       "      <td>瑞幸咖啡</td>\n",
       "      <td>餐饮服务;咖啡厅;咖啡厅</td>\n",
       "      <td>050500</td>\n",
       "      <td>diner</td>\n",
       "      <td>高盛大厦</td>\n",
       "      <td>113.321298,23.135921</td>\n",
       "      <td>[]</td>\n",
       "      <td>...</td>\n",
       "      <td>广州市</td>\n",
       "      <td>天河区</td>\n",
       "      <td>[]</td>\n",
       "      <td>[]</td>\n",
       "      <td>0</td>\n",
       "      <td>[]</td>\n",
       "      <td>[{'url': 'http://store.is.autonavi.com/showpic...</td>\n",
       "      <td>3.5</td>\n",
       "      <td>[]</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>B0FFKFTZS8</td>\n",
       "      <td>B00141JKC4</td>\n",
       "      <td>202</td>\n",
       "      <td>瑞幸咖啡</td>\n",
       "      <td>餐饮服务;咖啡厅;咖啡厅</td>\n",
       "      <td>050500</td>\n",
       "      <td>diner</td>\n",
       "      <td>南村镇兴南大道368号万达广场1F层</td>\n",
       "      <td>113.348032,23.006807</td>\n",
       "      <td>18617314707</td>\n",
       "      <td>...</td>\n",
       "      <td>广州市</td>\n",
       "      <td>番禺区</td>\n",
       "      <td>[]</td>\n",
       "      <td>[]</td>\n",
       "      <td>0</td>\n",
       "      <td>[]</td>\n",
       "      <td>[{'url': 'http://store.is.autonavi.com/showpic...</td>\n",
       "      <td>4.0</td>\n",
       "      <td>21.00</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>B0FFM3FC12</td>\n",
       "      <td>[]</td>\n",
       "      <td>[]</td>\n",
       "      <td>瑞幸咖啡</td>\n",
       "      <td>餐饮服务;咖啡厅;咖啡厅</td>\n",
       "      <td>050500</td>\n",
       "      <td>diner</td>\n",
       "      <td>五桂山街道长命水大街9号广东药科大学中山校区H栋一楼</td>\n",
       "      <td>113.414608,22.477310</td>\n",
       "      <td>[]</td>\n",
       "      <td>...</td>\n",
       "      <td>中山市</td>\n",
       "      <td>中山市</td>\n",
       "      <td>[]</td>\n",
       "      <td>[]</td>\n",
       "      <td>0</td>\n",
       "      <td>[]</td>\n",
       "      <td>[]</td>\n",
       "      <td>[]</td>\n",
       "      <td>[]</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>B0FFM232DZ</td>\n",
       "      <td>[]</td>\n",
       "      <td>[]</td>\n",
       "      <td>瑞幸咖啡</td>\n",
       "      <td>餐饮服务;咖啡厅;咖啡厅</td>\n",
       "      <td>050500</td>\n",
       "      <td>diner</td>\n",
       "      <td>常平镇市场路1号(永和大王隔壁)</td>\n",
       "      <td>113.994058,22.974066</td>\n",
       "      <td>[]</td>\n",
       "      <td>...</td>\n",
       "      <td>东莞市</td>\n",
       "      <td>东莞市</td>\n",
       "      <td>[]</td>\n",
       "      <td>[]</td>\n",
       "      <td>0</td>\n",
       "      <td>[]</td>\n",
       "      <td>[]</td>\n",
       "      <td>[]</td>\n",
       "      <td>[]</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>B0FFM0S65G</td>\n",
       "      <td>[]</td>\n",
       "      <td>[]</td>\n",
       "      <td>瑞幸咖啡</td>\n",
       "      <td>餐饮服务;咖啡厅;咖啡厅</td>\n",
       "      <td>050500</td>\n",
       "      <td>diner</td>\n",
       "      <td>同济西路12号永丰大厦1层正门口</td>\n",
       "      <td>113.105050,23.018770</td>\n",
       "      <td>[]</td>\n",
       "      <td>...</td>\n",
       "      <td>佛山市</td>\n",
       "      <td>禅城区</td>\n",
       "      <td>[]</td>\n",
       "      <td>[]</td>\n",
       "      <td>0</td>\n",
       "      <td>[]</td>\n",
       "      <td>[]</td>\n",
       "      <td>[]</td>\n",
       "      <td>[]</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>B0FFLNMOMV</td>\n",
       "      <td>B02F401BDW</td>\n",
       "      <td>202</td>\n",
       "      <td>瑞幸咖啡</td>\n",
       "      <td>餐饮服务;咖啡厅;咖啡厅</td>\n",
       "      <td>050500</td>\n",
       "      <td>diner</td>\n",
       "      <td>凤凰北路1015号丹田广场1楼</td>\n",
       "      <td>113.576182,22.279084</td>\n",
       "      <td>[]</td>\n",
       "      <td>...</td>\n",
       "      <td>珠海市</td>\n",
       "      <td>香洲区</td>\n",
       "      <td>[]</td>\n",
       "      <td>[]</td>\n",
       "      <td>0</td>\n",
       "      <td>[]</td>\n",
       "      <td>[]</td>\n",
       "      <td>[]</td>\n",
       "      <td>[]</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>B0FFLALYFU</td>\n",
       "      <td>B0FFIR09XN</td>\n",
       "      <td>202</td>\n",
       "      <td>瑞幸咖啡</td>\n",
       "      <td>餐饮服务;咖啡厅;咖啡厅</td>\n",
       "      <td>050500</td>\n",
       "      <td>diner</td>\n",
       "      <td>齐富路明珠路归南1号名汇电脑城一层外1FA003号</td>\n",
       "      <td>113.272173,23.194132</td>\n",
       "      <td>[]</td>\n",
       "      <td>...</td>\n",
       "      <td>广州市</td>\n",
       "      <td>白云区</td>\n",
       "      <td>[]</td>\n",
       "      <td>[]</td>\n",
       "      <td>0</td>\n",
       "      <td>[]</td>\n",
       "      <td>[]</td>\n",
       "      <td>[]</td>\n",
       "      <td>[]</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>B0FFM8OSUR</td>\n",
       "      <td>[]</td>\n",
       "      <td>[]</td>\n",
       "      <td>瑞幸咖啡</td>\n",
       "      <td>餐饮服务;咖啡厅;咖啡厅</td>\n",
       "      <td>050500</td>\n",
       "      <td>diner</td>\n",
       "      <td>古镇镇中兴大道南1号华艺广场亚朵酒店大堂27DA</td>\n",
       "      <td>113.189526,22.601383</td>\n",
       "      <td>[]</td>\n",
       "      <td>...</td>\n",
       "      <td>中山市</td>\n",
       "      <td>中山市</td>\n",
       "      <td>[]</td>\n",
       "      <td>[]</td>\n",
       "      <td>1</td>\n",
       "      <td>[]</td>\n",
       "      <td>[{'url': 'http://store.is.autonavi.com/showpic...</td>\n",
       "      <td>[]</td>\n",
       "      <td>[]</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>B0FFIWQMU9</td>\n",
       "      <td>B0FFG7M9YH</td>\n",
       "      <td>202</td>\n",
       "      <td>瑞幸咖啡</td>\n",
       "      <td>餐饮服务;咖啡厅;咖啡厅</td>\n",
       "      <td>050500</td>\n",
       "      <td>diner</td>\n",
       "      <td>沙太路668号现象工场1层</td>\n",
       "      <td>113.333927,23.178184</td>\n",
       "      <td>[]</td>\n",
       "      <td>...</td>\n",
       "      <td>广州市</td>\n",
       "      <td>白云区</td>\n",
       "      <td>[]</td>\n",
       "      <td>[]</td>\n",
       "      <td>0</td>\n",
       "      <td>[]</td>\n",
       "      <td>[{'url': 'http://store.is.autonavi.com/showpic...</td>\n",
       "      <td>3.5</td>\n",
       "      <td>19.00</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>B0FFIZI5MP</td>\n",
       "      <td>[]</td>\n",
       "      <td>[]</td>\n",
       "      <td>瑞幸咖啡</td>\n",
       "      <td>餐饮服务;咖啡厅;咖啡厅</td>\n",
       "      <td>050500</td>\n",
       "      <td>diner</td>\n",
       "      <td>大德路233号爱东精品酒店二楼餐厅</td>\n",
       "      <td>113.261406,23.118262</td>\n",
       "      <td>[]</td>\n",
       "      <td>...</td>\n",
       "      <td>广州市</td>\n",
       "      <td>越秀区</td>\n",
       "      <td>[]</td>\n",
       "      <td>[]</td>\n",
       "      <td>0</td>\n",
       "      <td>[]</td>\n",
       "      <td>[{'url': 'http://store.is.autonavi.com/showpic...</td>\n",
       "      <td>[]</td>\n",
       "      <td>[]</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>B0FFJS39AB</td>\n",
       "      <td>[]</td>\n",
       "      <td>[]</td>\n",
       "      <td>瑞幸咖啡</td>\n",
       "      <td>餐饮服务;咖啡厅;咖啡厅</td>\n",
       "      <td>050500</td>\n",
       "      <td>diner</td>\n",
       "      <td>东沙街道广州圆大厦1层</td>\n",
       "      <td>113.259121,23.050135</td>\n",
       "      <td>[]</td>\n",
       "      <td>...</td>\n",
       "      <td>广州市</td>\n",
       "      <td>荔湾区</td>\n",
       "      <td>[]</td>\n",
       "      <td>[]</td>\n",
       "      <td>0</td>\n",
       "      <td>[]</td>\n",
       "      <td>[{'url': 'http://store.is.autonavi.com/showpic...</td>\n",
       "      <td>3.5</td>\n",
       "      <td>[]</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>B0FFJOT0F8</td>\n",
       "      <td>B02F38OY21</td>\n",
       "      <td>202</td>\n",
       "      <td>瑞幸咖啡</td>\n",
       "      <td>餐饮服务;餐饮相关场所;餐饮相关</td>\n",
       "      <td>050000</td>\n",
       "      <td>diner</td>\n",
       "      <td>布吉街道广场路2号中安大厦一层大堂</td>\n",
       "      <td>114.127927,22.607544</td>\n",
       "      <td>[]</td>\n",
       "      <td>...</td>\n",
       "      <td>深圳市</td>\n",
       "      <td>龙岗区</td>\n",
       "      <td>[]</td>\n",
       "      <td>[]</td>\n",
       "      <td>0</td>\n",
       "      <td>[]</td>\n",
       "      <td>[{'url': 'http://store.is.autonavi.com/showpic...</td>\n",
       "      <td>3.5</td>\n",
       "      <td>20.00</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>B0FFJIQXEV</td>\n",
       "      <td>B0FFH1Z5DK</td>\n",
       "      <td>202</td>\n",
       "      <td>瑞幸咖啡</td>\n",
       "      <td>餐饮服务;咖啡厅;咖啡厅</td>\n",
       "      <td>050500</td>\n",
       "      <td>diner</td>\n",
       "      <td>广州大道中988号圣丰广场北塔一层109自编01号</td>\n",
       "      <td>113.315734,23.138347</td>\n",
       "      <td>[]</td>\n",
       "      <td>...</td>\n",
       "      <td>广州市</td>\n",
       "      <td>天河区</td>\n",
       "      <td>[]</td>\n",
       "      <td>[]</td>\n",
       "      <td>0</td>\n",
       "      <td>[]</td>\n",
       "      <td>[{'url': 'http://store.is.autonavi.com/showpic...</td>\n",
       "      <td>3.5</td>\n",
       "      <td>20.00</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>B0FFM10GH5</td>\n",
       "      <td>B0FFFOS5AN</td>\n",
       "      <td>202</td>\n",
       "      <td>瑞幸咖啡</td>\n",
       "      <td>餐饮服务;咖啡厅;咖啡厅</td>\n",
       "      <td>050500</td>\n",
       "      <td>diner</td>\n",
       "      <td>大沥镇广佛路97号美嘉广场首层</td>\n",
       "      <td>113.177122,23.107075</td>\n",
       "      <td>[]</td>\n",
       "      <td>...</td>\n",
       "      <td>佛山市</td>\n",
       "      <td>南海区</td>\n",
       "      <td>[]</td>\n",
       "      <td>[]</td>\n",
       "      <td>0</td>\n",
       "      <td>[]</td>\n",
       "      <td>[]</td>\n",
       "      <td>[]</td>\n",
       "      <td>[]</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16</th>\n",
       "      <td>B0FFJNBXAI</td>\n",
       "      <td>B02F37T14X</td>\n",
       "      <td>202</td>\n",
       "      <td>瑞幸咖啡</td>\n",
       "      <td>餐饮服务;咖啡厅;咖啡厅</td>\n",
       "      <td>050500</td>\n",
       "      <td>diner</td>\n",
       "      <td>中心区益田路4068号卓越时代广场负一层101-B-1号</td>\n",
       "      <td>114.057465,22.533943</td>\n",
       "      <td>[]</td>\n",
       "      <td>...</td>\n",
       "      <td>深圳市</td>\n",
       "      <td>福田区</td>\n",
       "      <td>[]</td>\n",
       "      <td>[]</td>\n",
       "      <td>0</td>\n",
       "      <td>[]</td>\n",
       "      <td>[{'url': 'http://store.is.autonavi.com/showpic...</td>\n",
       "      <td>4.0</td>\n",
       "      <td>19.00</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17</th>\n",
       "      <td>B0FFMB5YW8</td>\n",
       "      <td>[]</td>\n",
       "      <td>[]</td>\n",
       "      <td>瑞幸咖啡</td>\n",
       "      <td>餐饮服务;咖啡厅;咖啡厅</td>\n",
       "      <td>050500</td>\n",
       "      <td>diner</td>\n",
       "      <td>深南中路6009号</td>\n",
       "      <td>114.029891,22.535713</td>\n",
       "      <td>[]</td>\n",
       "      <td>...</td>\n",
       "      <td>深圳市</td>\n",
       "      <td>福田区</td>\n",
       "      <td>[]</td>\n",
       "      <td>[]</td>\n",
       "      <td>0</td>\n",
       "      <td>[]</td>\n",
       "      <td>[{'url': 'http://store.is.autonavi.com/showpic...</td>\n",
       "      <td>3.5</td>\n",
       "      <td>[]</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>18</th>\n",
       "      <td>B0FFM8X179</td>\n",
       "      <td>B0FFG9LHZV</td>\n",
       "      <td>202</td>\n",
       "      <td>瑞幸咖啡</td>\n",
       "      <td>餐饮服务;咖啡厅;咖啡厅</td>\n",
       "      <td>050500</td>\n",
       "      <td>diner</td>\n",
       "      <td>保税区富林物流大厦b栋</td>\n",
       "      <td>114.045120,22.506771</td>\n",
       "      <td>[]</td>\n",
       "      <td>...</td>\n",
       "      <td>深圳市</td>\n",
       "      <td>福田区</td>\n",
       "      <td>[]</td>\n",
       "      <td>[]</td>\n",
       "      <td>0</td>\n",
       "      <td>[]</td>\n",
       "      <td>[]</td>\n",
       "      <td>[]</td>\n",
       "      <td>[]</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>19</th>\n",
       "      <td>B0FFM1E650</td>\n",
       "      <td>[]</td>\n",
       "      <td>[]</td>\n",
       "      <td>瑞幸咖啡</td>\n",
       "      <td>餐饮服务;咖啡厅;咖啡厅</td>\n",
       "      <td>050500</td>\n",
       "      <td>diner</td>\n",
       "      <td>招商果岭6栋1123铺</td>\n",
       "      <td>113.858818,22.584051</td>\n",
       "      <td>[]</td>\n",
       "      <td>...</td>\n",
       "      <td>深圳市</td>\n",
       "      <td>宝安区</td>\n",
       "      <td>[]</td>\n",
       "      <td>[]</td>\n",
       "      <td>0</td>\n",
       "      <td>[]</td>\n",
       "      <td>[]</td>\n",
       "      <td>[]</td>\n",
       "      <td>[]</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>20 rows × 22 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "            id      parent childtype  name              type typecode  \\\n",
       "0   B0FFKJOM0K          []        []  瑞幸咖啡  餐饮服务;餐饮相关场所;餐饮相关   050000   \n",
       "1   B0FFJGBKD9  B0FFHGLFI2       202  瑞幸咖啡  餐饮服务;餐饮相关场所;餐饮相关   050000   \n",
       "2   B0FFJD4OEM          []        []  瑞幸咖啡      餐饮服务;咖啡厅;咖啡厅   050500   \n",
       "3   B0FFKFTZS8  B00141JKC4       202  瑞幸咖啡      餐饮服务;咖啡厅;咖啡厅   050500   \n",
       "4   B0FFM3FC12          []        []  瑞幸咖啡      餐饮服务;咖啡厅;咖啡厅   050500   \n",
       "5   B0FFM232DZ          []        []  瑞幸咖啡      餐饮服务;咖啡厅;咖啡厅   050500   \n",
       "6   B0FFM0S65G          []        []  瑞幸咖啡      餐饮服务;咖啡厅;咖啡厅   050500   \n",
       "7   B0FFLNMOMV  B02F401BDW       202  瑞幸咖啡      餐饮服务;咖啡厅;咖啡厅   050500   \n",
       "8   B0FFLALYFU  B0FFIR09XN       202  瑞幸咖啡      餐饮服务;咖啡厅;咖啡厅   050500   \n",
       "9   B0FFM8OSUR          []        []  瑞幸咖啡      餐饮服务;咖啡厅;咖啡厅   050500   \n",
       "10  B0FFIWQMU9  B0FFG7M9YH       202  瑞幸咖啡      餐饮服务;咖啡厅;咖啡厅   050500   \n",
       "11  B0FFIZI5MP          []        []  瑞幸咖啡      餐饮服务;咖啡厅;咖啡厅   050500   \n",
       "12  B0FFJS39AB          []        []  瑞幸咖啡      餐饮服务;咖啡厅;咖啡厅   050500   \n",
       "13  B0FFJOT0F8  B02F38OY21       202  瑞幸咖啡  餐饮服务;餐饮相关场所;餐饮相关   050000   \n",
       "14  B0FFJIQXEV  B0FFH1Z5DK       202  瑞幸咖啡      餐饮服务;咖啡厅;咖啡厅   050500   \n",
       "15  B0FFM10GH5  B0FFFOS5AN       202  瑞幸咖啡      餐饮服务;咖啡厅;咖啡厅   050500   \n",
       "16  B0FFJNBXAI  B02F37T14X       202  瑞幸咖啡      餐饮服务;咖啡厅;咖啡厅   050500   \n",
       "17  B0FFMB5YW8          []        []  瑞幸咖啡      餐饮服务;咖啡厅;咖啡厅   050500   \n",
       "18  B0FFM8X179  B0FFG9LHZV       202  瑞幸咖啡      餐饮服务;咖啡厅;咖啡厅   050500   \n",
       "19  B0FFM1E650          []        []  瑞幸咖啡      餐饮服务;咖啡厅;咖啡厅   050500   \n",
       "\n",
       "   biz_type                       address              location          tel  \\\n",
       "0     diner            梅界路237号奥园广场商业街121号  113.515126,22.282482  18529169274   \n",
       "1     diner     前进二路流塘商务大厦B座流塘湾购物中心一楼A12铺  113.890741,22.581641           []   \n",
       "2     diner                          高盛大厦  113.321298,23.135921           []   \n",
       "3     diner            南村镇兴南大道368号万达广场1F层  113.348032,23.006807  18617314707   \n",
       "4     diner    五桂山街道长命水大街9号广东药科大学中山校区H栋一楼  113.414608,22.477310           []   \n",
       "5     diner              常平镇市场路1号(永和大王隔壁)  113.994058,22.974066           []   \n",
       "6     diner              同济西路12号永丰大厦1层正门口  113.105050,23.018770           []   \n",
       "7     diner               凤凰北路1015号丹田广场1楼  113.576182,22.279084           []   \n",
       "8     diner     齐富路明珠路归南1号名汇电脑城一层外1FA003号  113.272173,23.194132           []   \n",
       "9     diner      古镇镇中兴大道南1号华艺广场亚朵酒店大堂27DA  113.189526,22.601383           []   \n",
       "10    diner                 沙太路668号现象工场1层  113.333927,23.178184           []   \n",
       "11    diner             大德路233号爱东精品酒店二楼餐厅  113.261406,23.118262           []   \n",
       "12    diner                   东沙街道广州圆大厦1层  113.259121,23.050135           []   \n",
       "13    diner             布吉街道广场路2号中安大厦一层大堂  114.127927,22.607544           []   \n",
       "14    diner     广州大道中988号圣丰广场北塔一层109自编01号  113.315734,23.138347           []   \n",
       "15    diner               大沥镇广佛路97号美嘉广场首层  113.177122,23.107075           []   \n",
       "16    diner  中心区益田路4068号卓越时代广场负一层101-B-1号  114.057465,22.533943           []   \n",
       "17    diner                     深南中路6009号  114.029891,22.535713           []   \n",
       "18    diner                   保税区富林物流大厦b栋  114.045120,22.506771           []   \n",
       "19    diner                   招商果岭6栋1123铺  113.858818,22.584051           []   \n",
       "\n",
       "    ... cityname adname importance shopid shopinfo poiweight  \\\n",
       "0   ...      珠海市    香洲区         []     []        0        []   \n",
       "1   ...      深圳市    宝安区         []     []        0        []   \n",
       "2   ...      广州市    天河区         []     []        0        []   \n",
       "3   ...      广州市    番禺区         []     []        0        []   \n",
       "4   ...      中山市    中山市         []     []        0        []   \n",
       "5   ...      东莞市    东莞市         []     []        0        []   \n",
       "6   ...      佛山市    禅城区         []     []        0        []   \n",
       "7   ...      珠海市    香洲区         []     []        0        []   \n",
       "8   ...      广州市    白云区         []     []        0        []   \n",
       "9   ...      中山市    中山市         []     []        1        []   \n",
       "10  ...      广州市    白云区         []     []        0        []   \n",
       "11  ...      广州市    越秀区         []     []        0        []   \n",
       "12  ...      广州市    荔湾区         []     []        0        []   \n",
       "13  ...      深圳市    龙岗区         []     []        0        []   \n",
       "14  ...      广州市    天河区         []     []        0        []   \n",
       "15  ...      佛山市    南海区         []     []        0        []   \n",
       "16  ...      深圳市    福田区         []     []        0        []   \n",
       "17  ...      深圳市    福田区         []     []        0        []   \n",
       "18  ...      深圳市    福田区         []     []        0        []   \n",
       "19  ...      深圳市    宝安区         []     []        0        []   \n",
       "\n",
       "                                               photos biz_ext.rating  \\\n",
       "0   [{'url': 'http://store.is.autonavi.com/showpic...            4.0   \n",
       "1   [{'url': 'http://store.is.autonavi.com/showpic...            3.5   \n",
       "2   [{'url': 'http://store.is.autonavi.com/showpic...            3.5   \n",
       "3   [{'url': 'http://store.is.autonavi.com/showpic...            4.0   \n",
       "4                                                  []             []   \n",
       "5                                                  []             []   \n",
       "6                                                  []             []   \n",
       "7                                                  []             []   \n",
       "8                                                  []             []   \n",
       "9   [{'url': 'http://store.is.autonavi.com/showpic...             []   \n",
       "10  [{'url': 'http://store.is.autonavi.com/showpic...            3.5   \n",
       "11  [{'url': 'http://store.is.autonavi.com/showpic...             []   \n",
       "12  [{'url': 'http://store.is.autonavi.com/showpic...            3.5   \n",
       "13  [{'url': 'http://store.is.autonavi.com/showpic...            3.5   \n",
       "14  [{'url': 'http://store.is.autonavi.com/showpic...            3.5   \n",
       "15                                                 []             []   \n",
       "16  [{'url': 'http://store.is.autonavi.com/showpic...            4.0   \n",
       "17  [{'url': 'http://store.is.autonavi.com/showpic...            3.5   \n",
       "18                                                 []             []   \n",
       "19                                                 []             []   \n",
       "\n",
       "   biz_ext.cost biz_ext.meal_ordering  \n",
       "0         17.00                     0  \n",
       "1         24.00                     0  \n",
       "2            []                     0  \n",
       "3         21.00                     0  \n",
       "4            []                     0  \n",
       "5            []                     0  \n",
       "6            []                     0  \n",
       "7            []                     0  \n",
       "8            []                     0  \n",
       "9            []                     0  \n",
       "10        19.00                     0  \n",
       "11           []                     0  \n",
       "12           []                     0  \n",
       "13        20.00                     0  \n",
       "14        20.00                     0  \n",
       "15           []                     0  \n",
       "16        19.00                     0  \n",
       "17           []                     0  \n",
       "18           []                     0  \n",
       "19           []                     0  \n",
       "\n",
       "[20 rows x 22 columns]"
      ]
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "parameters = {\n",
    "    'key':key,\n",
    "    'city':\"广东\",\n",
    "    'keywords':\"瑞幸咖啡\",\n",
    "    \"types\":\"餐饮服务\",\n",
    "    'output':'json',\n",
    "\n",
    "}\n",
    "r = requests.get (\"https://restapi.amap.com/v3/place/text?parameters\", params=parameters)\n",
    "data = r.json()\n",
    "pois = []\n",
    "pois.extend(data['pois'])\n",
    "data\n",
    "# import pandas as pd\n",
    "# df_input = pd.DataFrame(pois)\n",
    "# return df_input\n",
    "import pandas as pd\n",
    "cot = pd.json_normalize(data['pois'])\n",
    "cot"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "Empty DataFrame\n",
       "Columns: []\n",
       "Index: []"
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data = poi(\"瑞幸咖啡\",\"广东\")\n",
    "data\n",
    "# # pois = []\n",
    "# # pois.extend(data['pois'])\n",
    "# # import pandas as pd\n",
    "# # df_input = pd.DataFrame(pois)\n",
    "# # df_input"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### IP定位\n",
    "- IP定位是一个简单的HTTP接口，根据用户输入的IP地址，能够快速的帮用户定位IP的所在位置。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 165,
   "metadata": {},
   "outputs": [],
   "source": [
    "def ip(ip:str):\n",
    "    \"\"\"IP定位可以帮你定位ip的所在位置，输入对应ip即可\"\"\"\n",
    "    parameters = {\n",
    "        'key':key,\n",
    "        'ip':ip,\n",
    "        'output':'json'\n",
    "    }\n",
    "    r = requests.get (\"https://restapi.amap.com/v3/ip?parameters\", params=parameters)\n",
    "    data = r.json()\n",
    "    del data['status']\n",
    "    del data['info']\n",
    "    df = [\"省份：%s\"%(data['province']),\"地区：%s\"%(data['city']),\"地理编码：%s\"%(data['adcode']),\"经纬度： %s\"%(data['rectangle'])]\n",
    "    print(\"ip:\"+ip)\n",
    "    for i in df:\n",
    "        print(i)\n",
    "    return    \n",
    "    \n",
    "   \n",
    "   \n",
    "    \n",
    "    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 166,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "ip:182.254.192.28\n",
      "省份：广东省\n",
      "地区：广州市\n",
      "地理编码：440100\n",
      "经纬度： 113.1017375,22.93212254;113.6770499,23.3809537\n"
     ]
    }
   ],
   "source": [
    "ip(\"182.254.192.28\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 静态地图"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "- 静态地图服务通过返回一张地图图片响应HTTP请求，使用户能够将高德地图以图片形式嵌入自己的网页中。用户可以指定请求的地图位置、图片大小、以及在地图上添加覆盖物，如标签、标注、折线、多边形。\n",
    "\n",
    "- 静态地图在使用的过程中，需要遵守高德开放平台[《自定义地图服务协议》](https://lbs.amap.com/home/customize-map-terms/)。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "metadata": {},
   "outputs": [],
   "source": [
    "def map(location:str,zoom:str):\n",
    "    \"\"\"zoom：设置地图大小\n",
    "       location：选择地图中心坐标\n",
    "    \"\"\"\n",
    "    parameters = {\n",
    "        'key':key,\n",
    "        'location':location,\n",
    "        'zoom':zoom,\n",
    "        \n",
    "    }\n",
    "    r = requests.get (\"https://restapi.amap.com/v3/staticmap?parameters\", params=parameters)\n",
    "    data = r.url\n",
    "    return data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'https://restapi.amap.com/v3/staticmap?parameters&key=d9d5fa5d72ce3bcf4a2fee373f2e81af&location=113.679287%2C23.632575&zoom=18'"
      ]
     },
     "execution_count": 44,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "map(geo(\"广东省广州市从化区中山大学南方学院\",\"广州\"),18)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "![0](https://restapi.amap.com/v3/staticmap?parameters&key=d9d5fa5d72ce3bcf4a2fee373f2e81af&location=113.679287%2C23.632575&zoom=18)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 235,
   "metadata": {},
   "outputs": [],
   "source": [
    "# import matplotlib.pyplot as plt # plt 用于显示图片\n",
    "# import matplotlib.image as mpimg # mpimg 用于读取图片\n",
    "# import numpy as np\n",
    " \n",
    "# lena = mpimg.imread(BytesIO(requests.get('https://restapi.amap.com/v3/staticmap?parameters&key=d9d5fa5d72ce3bcf4a2fee373f2e81af&location=113.679287%2C23.632575&zoom=8').content)) # 读取和代码处于同一目录下的 lena.png\n",
    "# # 此时 lena 就已经是一个 np.array 了，可以对它进行任意处理\n",
    "# lena.shape #(512, 512, 3)\n",
    " \n",
    "# plt.imshow(lena) # 显示图片\n",
    "# plt.axis('off') # 不显示坐标轴\n",
    "# plt.show()\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 坐标转换\n",
    "- 坐标转换是一类简单的HTTP接口，能够将用户输入的非高德坐标（GPS坐标、mapbar坐标、baidu坐标）转换成高德坐标。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [],
   "source": [
    "def assistant(locations:str,coordsys:str):\n",
    "    \"\"\"坐标转换\n",
    "    locations填入非高德坐标\n",
    "    coordsys可选值：gps,mapbar,baidu,autonavi（不进行转换）\n",
    "    \"\"\"\n",
    "    parameters = {\n",
    "        'key':key,\n",
    "        'coordsys':coordsys,\n",
    "        'locations':locations,\n",
    "        'output':'json'\n",
    "    }\n",
    "    r = requests.get (\"https://restapi.amap.com/v3/assistant/coordinate/convert?parameters\", params=parameters)\n",
    "    data = r.json()['locations']\n",
    "    return data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'116.487585177952,39.991754014757;116.487585177952,39.991653917101'"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "assistant(\"116.481499,39.990475|116.481499,39.990375\",'gps')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 天气查询\n",
    "- 天气查询是一个简单的HTTP接口，根据用户输入的adcode，查询目标区域当前/未来的天气情况。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 52,
   "metadata": {},
   "outputs": [],
   "source": [
    "def weather(city:str):\n",
    "    \"\"\"天气查询\n",
    "    查询当地天气情况\"\"\"\n",
    "    parameters = {\n",
    "        'key':key,\n",
    "        'city':city,\n",
    "        'output':'json'\n",
    "    }\n",
    "    r = requests.get (\"https://restapi.amap.com/v3/weather/weatherInfo?parameters\", params=parameters)\n",
    "    data = r.json()\n",
    "    \n",
    "    return data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 53,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'status': '1',\n",
       " 'count': '1',\n",
       " 'info': 'OK',\n",
       " 'infocode': '10000',\n",
       " 'lives': [{'province': '广东',\n",
       "   'city': '广州市',\n",
       "   'adcode': '440100',\n",
       "   'weather': '晴',\n",
       "   'temperature': '23',\n",
       "   'winddirection': '东北',\n",
       "   'windpower': '≤3',\n",
       "   'humidity': '70',\n",
       "   'reporttime': '2019-10-16 23:45:09'}]}"
      ]
     },
     "execution_count": 53,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "weather('广州')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 输入提示\n",
    "- 输入提示是一类简单的HTTP接口，提供根据用户输入的关键词查询返回建议列表。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 177,
   "metadata": {},
   "outputs": [],
   "source": [
    "def inputtips(keywords:str):\n",
    "    \"\"\"填写关键词课查询\"\"\"\n",
    "    parameters = {\n",
    "        'key':key,\n",
    "        'keywords':keywords,\n",
    "        'output':'json'\n",
    "    }\n",
    "    r = requests.get (\"https://restapi.amap.com/v3/assistant/inputtips?parameters\", params=parameters)\n",
    "    data = r.json()\n",
    "    return data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 178,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'status': '1',\n",
       " 'count': '10',\n",
       " 'info': 'OK',\n",
       " 'infocode': '10000',\n",
       " 'tips': [{'id': 'B00141IHRZ',\n",
       "   'name': '中山大学广州校区南校园',\n",
       "   'district': '广东省广州市海珠区',\n",
       "   'adcode': '440105',\n",
       "   'location': '113.298379,23.096705',\n",
       "   'address': '新港西路135号',\n",
       "   'typecode': '141201',\n",
       "   'city': []},\n",
       "  {'id': 'B02F402P24',\n",
       "   'name': '中山大学珠海校区',\n",
       "   'district': '广东省珠海市香洲区',\n",
       "   'adcode': '440402',\n",
       "   'location': '113.586266,22.349455',\n",
       "   'address': '唐淇路',\n",
       "   'typecode': '141201',\n",
       "   'city': []},\n",
       "  {'id': 'B0FFK8L6A0',\n",
       "   'name': '中山大学北校区',\n",
       "   'district': '广东省广州市越秀区',\n",
       "   'adcode': '440104',\n",
       "   'location': '113.290008,23.128634',\n",
       "   'address': '东风东路658号',\n",
       "   'typecode': '141201',\n",
       "   'city': []},\n",
       "  {'id': 'B00140NUN1',\n",
       "   'name': '中山大学附属第六医院',\n",
       "   'district': '广东省广州市天河区',\n",
       "   'adcode': '440106',\n",
       "   'location': '113.364148,23.118217',\n",
       "   'address': '员村二横路26号(本部区)',\n",
       "   'typecode': '090101',\n",
       "   'city': []},\n",
       "  {'id': 'B03017WMXK',\n",
       "   'name': '中山大学附属东华医院',\n",
       "   'district': '广东省东莞市',\n",
       "   'adcode': '441900',\n",
       "   'location': '113.786305,23.030219',\n",
       "   'address': '东城东路1号',\n",
       "   'typecode': '090101',\n",
       "   'city': []},\n",
       "  {'id': 'B00140TAV2',\n",
       "   'name': '中山大学南校区(北门)',\n",
       "   'district': '广东省广州市海珠区',\n",
       "   'adcode': '440105',\n",
       "   'location': '113.300039,23.102687',\n",
       "   'address': '新港西路135号中山大学南校区东北区398号',\n",
       "   'typecode': '990000',\n",
       "   'city': []},\n",
       "  {'id': 'B00140KFHA',\n",
       "   'name': '中山大学附属肿瘤医院',\n",
       "   'district': '广东省广州市越秀区',\n",
       "   'adcode': '440104',\n",
       "   'location': '113.2901,23.131375',\n",
       "   'address': '东风东路651',\n",
       "   'typecode': '090207',\n",
       "   'city': []},\n",
       "  {'id': 'BV10250173',\n",
       "   'name': '中山大学(公交站)',\n",
       "   'district': '广东省珠海市香洲区',\n",
       "   'adcode': '440402',\n",
       "   'location': '113.593132,22.348196',\n",
       "   'address': '10A路;10路;3A路;3路;66路;68路;69路;85路;B20路;K1路;K3路',\n",
       "   'typecode': '150700',\n",
       "   'city': []},\n",
       "  {'id': 'B00140226E',\n",
       "   'name': '中山大学附属第一医院',\n",
       "   'district': '广东省广州市越秀区',\n",
       "   'adcode': '440104',\n",
       "   'location': '113.291201,23.126353',\n",
       "   'address': '中山二路58号',\n",
       "   'typecode': '090101',\n",
       "   'city': []},\n",
       "  {'id': 'B02F400ISX',\n",
       "   'name': '中山大学附属第五医院',\n",
       "   'district': '广东省珠海市香洲区',\n",
       "   'adcode': '440402',\n",
       "   'location': '113.573232,22.298373',\n",
       "   'address': '梅华东路52号',\n",
       "   'typecode': '090101',\n",
       "   'city': []}]}"
      ]
     },
     "execution_count": 178,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "inputtips(\"中山大学\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 交通态势\n",
    "- 交通态势是一类简单的HTTP接口，提供根据用户输入的内容能够返回希望查询的交通态势情况。\n",
    "\n",
    "- 目前支持城市：北京，上海，广州，深圳，宁波，武汉，重庆，成都，沈阳，南京，杭州，长春，常州，大连，东莞，福州，青岛，石家庄，天津，太原，西安，无锡，厦门，珠海，长沙，苏州，金华，佛山，济南，泉州，嘉兴，西宁，惠州，温州，中山，合肥，乌鲁木齐，台州，绍兴，昆明。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 63,
   "metadata": {},
   "outputs": [],
   "source": [
    "def rectangle(rectangle:str):\n",
    "    \"\"\"rectangle:填写查询的经纬度\"\"\"\n",
    "    parameters = {\n",
    "        'key':key,\n",
    "        'rectangle':rectangle,\n",
    "        'output':'json'\n",
    "    }\n",
    "    r = requests.get (\"https://restapi.amap.com/v3/traffic/status/rectangle?parameters\", params=parameters)\n",
    "    data = r.json()\n",
    "    return data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 64,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'status': '1',\n",
       " 'info': 'OK',\n",
       " 'infocode': '10000',\n",
       " 'trafficinfo': {'description': '京藏高速：北沙滩桥附近出京方向行驶缓慢。',\n",
       "  'evaluation': {'expedite': '92.86%',\n",
       "   'congested': '7.14%',\n",
       "   'blocked': '0.00%',\n",
       "   'unknown': '0.00%',\n",
       "   'status': '2',\n",
       "   'description': '轻度拥堵'}}}"
      ]
     },
     "execution_count": 64,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "rectangle(\"116.351147,39.966309;116.357134,39.968727\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 简单的应用"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 盲人出行路线指引应用\n",
    "#### 一、所调用的高德API：\n",
    "- 路径规划；\n",
    "- 交通态势；\n",
    "- IP定位\n",
    "\n",
    "#### 二、产品需求：\n",
    "- 现如今，关于人们出行的导航类软件层出不穷，越来越多的APP或者小程序都在开发类似的产品，但是专门做盲人出现路线的指导产品却少之又少。针对这个用户痛点，结合高德地图有关的API，打造一个专属盲人出现的路线指引，满足一部分用户的需求。\n",
    "\n",
    "#### 三、产品描述：\n",
    "- 盲人出行路线指引是以语音识别功能为基础的。用户根据语音提示输入要到达的目的地。应用再根据IP定位功能，实行路径规划和交通态势的分析，为用户选择最方便快捷、障碍最少或者交通状况最优的路线。帮助用户解决出行困难的问题。\n",
    "\n",
    "#### 四、产品结构\n",
    "\n",
    "![知识结构](https://github.com/zhengxiaopingzxp/gd_API/blob/master/%E5%9B%BE%E7%89%871.png?raw=true)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.3"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": true
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
